import { defineStore } from "pinia";
import { ref } from "vue";
export const useUserStore = defineStore(
    'user',
     () => {
        const token = ref<string | null>('');
        // 设置token
         const setToken = (newToken: string) => {
               token.value = newToken;
               localStorage.setItem('pinia_token', newToken);
         }
         // 清除token
         const clearToken = () =>{
            token.value = null;
            localStorage.removeItem('pinia_token');
         }
         // 获取当前token（用于请求头）
         const getToken = () => token.value;
        return { token,setToken,clearToken ,getToken};
     },
     {
        //开启持久化配置     无法实现！！！
         // persist: true
     }
    )